<?php

/**
 * Class Lib_Repair_Adapter_YiDong
 * 移动失联修复
 * 2018/05/30
 */
class Lib_Repair_Adapter_YiDong extends Lib_Repair_Base_Abstract
{

    /**
     * 修复接口
     * @param $data
     * @return array
     */
    public function repair($data) {
        try {
            if($data){
                $repairData = $data['repairData'];
                $repair_num = count($repairData);
                if($repair_num == 0 ){
                    //没有课修复数据
                    return  [
                        'code' => 400,
                        'message' => 'empty data',
                        'data' => [],
                    ];
                }
                $limit = 0;
                if($repair_num < $limit){
                    $differ_num = $limit - $repair_num;
                    for ($x=1; $x<=$differ_num; $x++) {
                        $repairData[] = [
                            'repairerName' => "张三",
                            'idCard' => "63640264849a87c90356129d99ea165e37aa5fabc1fea46906df1a7ca50db492",//hash("sha256", '12345678910')
                        ];
                    }
                }
                $result = Lib_Repair_Implement_YiDong::getInstance()->repair($repairData);
                if(!$result['success'] && empty($result['data'])){
                    Func_Log::write('repair',   'yindong',"submit repair -- error ".' responsedata: '. json_encode($result));
                    return  [
                        'code' => 400,
                        'message' => $result['msg'],
                        'data' => [],
                    ];
                }
                return  [
                    'code' => 200,
                    'message' => $result['message'],
                    'data' => [
                        'batchNo' => $result['data']['batchNo']
                    ],
                ];
                Func_Log::write('repair',   'yindong',"submit repair -- success ".' responsedata: '. json_encode($result));
            }
            return  [
                'code' => 400,
                'message' => 'empty data',
                'data' => [],
            ];
        } catch (Exception $exception) {
            Func_Log::write('Exception',  'yindong','loss repair -- ' .$exception->getMessage().' responsedata : '. json_encode($data));
            return  [
                'code' => 500,
                'message' => $exception->getMessage(),
                'data' => [],
            ];

        }
    }

    /**
     * 获取拨打的号码
     * @param $data
     * @return array
     */
    public function bindTel($data){

        try {
            $result = Lib_Repair_Implement_YiDong::getInstance()->binding($data);

            if(!$result['success'] && empty($result['data'])){
                Func_Log::write('repair',   'yindong',"bindTel -- error ".' responsedata: '. json_encode($result));
                return  [
                    'code' => 400,
                    'message' => $result['msg'],
                    'data' => [],
                ];
            }
            return  [
                'code' => 200,
                'message' => $result['message'],
                'data' => [
                    'toTel'=>$result['data']['virtualNo'],
                    'bindId' => $result['data']['bindId'],
                ],
            ];
            Func_Log::write('repair',   'yindong',"bindTel -- success ".' responsedata: '. json_encode($result));
        } catch (Exception $exception) {
            Func_Log::write('repair',   'yindong','bindTel --'.$exception->getMessage().' responsedata: '. json_encode($data));
            return ['code'=>500,'message' => "serve error" ,'data'=>[]];

        }
    }
    public function unbinding($data){

    }
    public function sendSms($data)
    {
        // TODO: Implement sendSms() method.
    }


}